package com.settlement.system.service.csv;

import com.settlement.system.common.enums.CostAllocationEnum;
import com.settlement.system.model.entity.common.TblUnificationBillSummary;
import com.settlement.system.service.IBaseService;
import com.settlement.system.service.ITblRrBillTypeService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;

import java.util.Map;

/**
 * 订单稽核导出
 *
 * @author Ximi
 * @since 2020/10/24
 */
@Slf4j
public class TblUnificationBillDetailCsvDatas extends BaseServiceCsvDatas {

    private ITblRrBillTypeService tblRrBillTypeService;

    public TblUnificationBillDetailCsvDatas(IBaseService baseService,
                                            Map<String, Object> params,
                                            ITblRrBillTypeService tblRrBillTypeService) {
        super(baseService, params);
        this.tblRrBillTypeService = tblRrBillTypeService;
    }

    @Override
    public Object beforeWrite(Object data) {
//        if (data instanceof TblUnificationBillDetail) {
//            TblUnificationBillDetail detail = (TblUnificationBillDetail) data;
//            String billTypeNo = detail.getBillType();
//            if(StringUtils.isNotEmpty(billTypeNo)){
//                String nameByNo = tblRrBillTypeService.getNameByNo(billTypeNo);
//                detail.setBillType(nameByNo);
//            }
//            return detail;
//        }
        if (data instanceof TblUnificationBillSummary) {
            TblUnificationBillSummary detail = (TblUnificationBillSummary) data;
            if(StringUtils.isEmpty(detail.getShareStatus())){
                if(CostAllocationEnum.ShareOrNotEnum.YES.getNo().equals(detail.getShareOrNot())){
                    detail.setShareStatus(CostAllocationEnum.ShareStatusEnum.T1.getNo());
                }else if(CostAllocationEnum.ShareOrNotEnum.NO.getNo().equals(detail.getShareOrNot())){
                    detail.setShareStatus(CostAllocationEnum.ShareStatusEnum.T0.getNo());
                }
            }
            return detail;
        }
        return data;
    }
}
